<!--  藏头诗生成 API-->
<template>
  <div class="container">

    <!--  面包屑导航 -->
    <nav aria-label="breadcrumb">
      <ol class="breadcrumb">
        <li class="breadcrumb-item"><a href="/onlinetool/#/">首页</a></li>
        <li class="breadcrumb-item"><a href="#">休闲娱乐</a></li>
        <li class="breadcrumb-item active" aria-current="page">藏头诗生成</li>
      </ol>
    </nav>

    <!--  头部卡片  -->
    <div class="card border-primary ">
      <!--  放在 .card 里面的标签默认宽度会占满父元素宽度, 所以 a 标签应该放在 .card-body 里面-->
      <div class="card-header bg-info">藏头诗</div>
      <div class="card-body ">
        <h5 class="card-title text-primary">生成一首藏头诗</h5>
        <p class="card-text"></p>
        <button type="button" @click="getHeadPoem" class="btn btn-outline-success">生成藏头诗</button>

        <div class="form-group mx-sm-3 mb-2 d-inline-block">
          <input type="text" v-model="title" class="form-control" id="inputPassword2" placeholder="请输入藏字内容">
        </div>

        <!--  旋转提示组件  -->
        <div class="spinner-border text-success ml-5" role="status">
          <span class="sr-only">Loading...</span>
        </div>
      </div>
    </div>

    <div class="list-group mt-3">
      <div class="list-group-item list-group-item-action">
        <p class="mb-1 text-center">{{ titlePoem.list }}</p>
      </div>
    </div>


  </div>
</template>

<script>
  export default {
    name: 'HeadPoem',
    data() {
      return {
        title: "",
        titlePoem: {}
      }
    },
    methods: {
      async getHeadPoem() {
        this.$(".spinner-border").css("display", "inline-block");

        const result = await this.$http.get("http://api.tianapi.com/txapi/cangtoushi/index?key=d1032a21949c41bbf6a472ec75a94e2a&word=" + this.title);
        this.titlePoem = result.data.newslist[0];
        if (this.weatherPoem !== null) {
          this.$(".spinner-border").css("display", "none");
        }


      }
    }
  }
</script>

<style scoped>
  .spinner-border {
    display: none;
  }

  .poem-title p {
    font-size: 20px;
  }
</style>
